﻿/************************************************
 * Copyright (C) 2011 东北农业大学(NEAU)
 * 版权所有。
 * 文件名：ContactsTypeDel.aspx.cs
 * 版本号：v1.0
 * 文件功能描述：通讯录类别的删除
 * 作者：侯建
 * 创建日期：2011.04.08
************************************************/
using System;
using System.Collections.Generic;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Collections;
using Jxym.DBUtility;

namespace Jxym.wlkc2011.Module.Default.server.Contacts
{
    public partial class ContactsTypeDel : System.Web.UI.Page
    {
        protected void Page_Load(object sender, EventArgs e)
        {
            if (!IsPostBack)
            {
                
                int modelid = 0;
                if (Request.Params["modelid"] != null) modelid = Convert.ToInt32(Request.Params["modelid"]);
                //验证用户权限
                if (MyGet.GetPermissionsValidation(modelid, "D", Jxym.Common.Request.AdminID("user")))
                {
                    string returnVaoue = "", listIds = ""; ;

                    ArrayList list = new ArrayList();

                    if (Request.Params["CommunityClassid"] != null)
                    {
                        string idstr = Request.Params["CommunityClassid"];

                        string[] ids = idstr.Split(',');

                        MsSqlDal<model.ContactsType> iUi = new MsSqlDal<model.ContactsType>();

                        foreach (string id in ids)
                        {
                            //判断该通知发布人是不是当前用户
                            model.ContactsType com = iUi.GetModel("ContactsTypeID = " + id, null);
                            if (Jxym.Common.Request.AdminID("user").Equals(com.AddUser.ToString()))
                            {
                                try
                                {
                                    int count = 0;

                                    count = iUi.Delete("ContactsTypeID = " + id, null);

                                    if (count > 0) { list.Add(id); }
                                }
                                catch (Exception)
                                {

                                }
                            }
                        }
                        if (list.Count > 0)
                        {
                            foreach (string id in list)
                            {
                                listIds += id + ",";
                            }

                            listIds = listIds.TrimEnd(',');

                            Response.Write("{'success':true,'count':" + list.Count + ",'ids':'" + listIds + "','msg':'" + returnVaoue + "'}");
                        }
                        else
                        {
                            Response.Write("{'success':false,'msg':'对不起，您没有删除权限'}");
                        }
                    }
                }
                else
                {
                    Response.Write("{'success':false,'msg':'对不起，您没有删除权限'}");
                }
            }
        }
    }
}